STORE 0 TO PL5,PL6,ORD,PL7,PL8
DO WHILE PL5=0 .AND. LASTKEY()<>27
   SET COLOR TO BG/B
   @ 8,1 CLEA TO 23,78
   NUM=ST_MAX-ST_ACT_BUY
   DO BOXT WITH 8,1,'CODE : '+KODE+',  '+ALLTRIM(NAME)+'  '+ALLTRIM(TIPE)+',  '+ALLTRIM(QANT)+' '+ALLTRIM(UNIT),'W+','B',.F.,.F.
   DO CASE
      CASE BUY_SELL_R>1 .AND. (RIGHT(ALLTRIM(SELL_UNIT),1)='X' .OR. RIGHT(ALLTRIM(SELL_UNIT),1)='S')
         DO BOXT WITH 10,1,'MINIMUM LEVEL : '+ALLTRIM(TRANS(ST_REFIL,'99,999'))+' '+ALLTRIM(BUY_UNIT)+' of '+ALLTRIM(TRANS(BUY_SELL_R,'9,999'))+' '+ALLTRIM(SELL_UNIT)+'ES','W+','B',.F.,.F.
      CASE BUY_SELL_R>1 .AND. RIGHT(ALLTRIM(SELL_UNIT),1)<>'X' .AND. RIGHT(ALLTRIM(SELL_UNIT),1)<>'S'
         DO BOXT WITH 10,1,'MINIMUM LEVEL : '+ALLTRIM(TRANS(ST_REFIL,'99,999'))+' '+ALLTRIM(BUY_UNIT)+' of '+ALLTRIM(TRANS(BUY_SELL_R,'9,999'))+' '+ALLTRIM(SELL_UNIT)+'S','W+','B',.F.,.F.
      CASE BUY_SELL_R=1 .AND. ST_REFIL>1
         DO BOXT WITH 10,1,'MINIMUM LEVEL : '+ALLTRIM(TRANS(ST_REFIL,'99,999'))+' '+ALLTRIM(BUY_UNIT)+'S','W+','B',.F.,.F.
      CASE BUY_SELL_R=1 .AND. ST_REFIL=1
         DO BOXT WITH 10,1,'MINIMUM LEVEL : '+ALLTRIM(TRANS(ST_REFIL,'99,999'))+' '+ALLTRIM(BUY_UNIT),'W+','B',.F.,.F.
   ENDCASE
   DO CASE
      CASE ST_MAX>1 .AND. RIGHT(ALLTRIM(BUY_UNIT),1)<>'X' .AND. RIGHT(ALLTRIM(BUY_UNIT),1)<>'S'
         DO BOXT WITH 10,41,'MAXIMUM LEVEL : '+ALLTRIM(TRANS(ST_MAX,'99,999'))+' '+ALLTRIM(BUY_UNIT)+'S','W+','B',.F.,.F.
      CASE ST_MAX>1 .AND. (RIGHT(ALLTRIM(BUY_UNIT),1)='X' .OR. RIGHT(ALLTRIM(BUY_UNIT),1)='S')
         DO BOXT WITH 10,41,'MAXIMUM LEVEL : '+ALLTRIM(TRANS(ST_MAX,'99,999'))+' '+ALLTRIM(BUY_UNIT)+'ES','W+','B',.F.,.F.
      OTHER
         DO BOXT WITH 10,41,'MAXIMUM LEVEL : '+ALLTRIM(TRANS(ST_MAX,'99,999'))+' '+ALLTRIM(BUY_UNIT),'W+','B',.F.,.F.
   ENDCASE
   DO CASE
      CASE ST_ACT_BUY>1 .AND. RIGHT(ALLTRIM(BUY_UNIT),1)<>'X' .AND. RIGHT(ALLTRIM(BUY_UNIT),1)<>'S'
         DO BOXT WITH 12,1,'PHYSICAL BALANCE : '+ALLTRIM(TRANS(ST_ACT_BUY,'99,999'))+' '+ALLTRIM(BUY_UNIT)+'S','W+','B',.F.,.F.
     CASE ST_ACT_BUY>1 .AND. (RIGHT(ALLTRIM(BUY_UNIT),1)='X' .OR. RIGHT(ALLTRIM(BUY_UNIT),1)='S')
         DO BOXT WITH 12,1,'PHYSICAL BALANCE : '+ALLTRIM(TRANS(ST_ACT_BUY,'99,999'))+' '+ALLTRIM(BUY_UNIT)+'ES','W+','B',.F.,.F.
     OTHER
        DO BOXT WITH 12,1,'PHYSICAL BALANCE : '+ALLTRIM(TRANS(ST_ACT_BUY,'99,999'))+' '+ALLTRIM(BUY_UNIT),'W+','B',.F.,.F.
   ENDCASE
   IF ST_MAX-ST_ACT_BUY>0
      DO CASE
         CASE ST_MAX-ST_ACT_BUY>1 .AND. RIGHT(ALLTRIM(BUY_UNIT),1)<>'X' .AND. RIGHT(ALLTRIM(BUY_UNIT),1)<>'S'
            DO BOXT WITH 14,1,'RECOMMENDED RE-ORDER : '+ALLTRIM(TRANS(ST_MAX-ST_ACT_BUY,'99,999'))+' '+ALLTRIM(BUY_UNIT)+'S','gr+','B',.F.,.F.
         CASE ST_MAX-ST_ACT_BUY>1 .AND. (RIGHT(ALLTRIM(BUY_UNIT),1)='X' .OR. RIGHT(ALLTRIM(BUY_UNIT),1)='S')
            DO BOXT WITH 14,1,'RECOMMENDED RE-ORDER : '+ALLTRIM(TRANS(ST_MAX-ST_ACT_BUY,'99,999'))+' '+ALLTRIM(BUY_UNIT)+'ES','gr+','B',.F.,.F.
         OTHER
            DO BOXT WITH 14,1,'RECOMMENDED RE-ORDER : '+ALLTRIM(TRANS(ST_MAX-ST_ACT_BUY,'99,999'))+' '+ALLTRIM(BUY_UNIT),'gr+','B',.F.,.F.
      ENDCASE
   ELSE
      DO BOXT WITH 14,1,'NOT RECOMMENDED , OVER THE MAXIMUM STOCK : '+ALLTRIM(TRANS(ABS(ST_MAX-ST_ACT_BUY),'99,999'))+' '+ALLTRIM(BUY_UNIT),'gr+','B',.F.,.F.
   ENDIF
   SET COLOR TO BG/B
   @ 18, 1 CLEA TO 23,78
   DO BOX2 WITH 12,51,'RE-ORDER ? :','YES','NO','GR+','R','W+','N',PL5,.F.,.T.
   IF PL5=1
      DO WHILE PL6=0 .AND. LASTKEY()<>27
         DO BOX2 WITH 17,1,'ACCEPT SUGGESTED RE-ORDER :','YES','NO','GR+','R','W+','N',PL6,.T.,.T.
         SET COLOR TO BG/B
         @ 17,1 CLEA TO 23,78
         IF PL6=2
            IF RIGHT(ALLTRIM(BUY_UNIT),1)='X' .OR. RIGHT(ALLTRIM(BUY_UNIT),1)='S'
               DO BOXN WITH 17,1,"INPUT REQUESTED ORDER (NUMBER of "+ALLTRIM(BUY_UNIT)+'ES) :','ORD','9,999','GR+','B','W+','N','10000','0',.F.,.F.
           ELSE
               DO BOXN WITH 17,1,"INPUT REQUESTED ORDER (NUMBER of "+ALLTRIM(BUY_UNIT)+'S) :','ORD','9,999','GR+','B','W+','N','10000','0',.F.,.F.
            ENDIF
         ELSE
            IF RIGHT(ALLTRIM(BUY_UNIT),1)='X' .OR. RIGHT(ALLTRIM(BUY_UNIT),1)='S'
               DO BOXT WITH 17,1,"REQUESTED ORDER (NUMBER of "+ALLTRIM(BUY_UNIT)+'ES) : '+ALLTRIM(TRANS(st_max-st_act_buy,'99,999')),'GR+','B',.F.,.F.
           ELSE
               DO BOXT WITH 17,1,"REQUESTED ORDER (NUMBER of "+ALLTRIM(BUY_UNIT)+'S) : '+ALLTRIM(TRANS(st_max-st_act_buy,'99,999')),'GR+','B',.F.,.F.
            ENDIF
         ENDIF
      ENDDO
      DO WHILE PL7=0 .AND. LASTKEY()<>27
         DO BOX2 WITH 20,46,'DO YOU CONFIRM :','YES','NO','GR+','R','W+','N',PL7,.T.,.T.
         IF PL7=1
            NEXT=.T.
            IF REC_LOCK(0)
               REPL ST_RE_PROP WITH .T.
               IF PL6=1
                  REPL ST_RE_QANT WITH num
               ELSE
                  REPL ST_RE_QANT WITH ORD
               ENDIF
            ENDIF
            UNLOCK
         else
            DO BOX2 WITH 20,1,'DO YOU WANT TO RETRY :','YES','NO','GR+','R','W+','N',PL8,.T.,.T.
            if pl8=1
               NEXT=.F.
            ELSE
               NEXT=.T.
            endif
         ENDIF
      ENDDO
   ELSE
      NEXT=.T.
   ENDIF
ENDDO
